# Contributor: Alex Yam <alex@alexyam.com>
# Maintainer: Alex Yam <alex@alexyam.com>
pkgname=fcitx5-gtk
pkgver=5.0.16
pkgrel=0
pkgdesc="Fcitx5 GTK module"
url="https://github.com/fcitx/fcitx5-gtk/"
arch="all !armhf !riscv64 !s390x" # armhf:extra-cmake-modules, riscv64/s390x:gtk4
license="LGPL-2.1-or-later"
depends="fcitx5"
makedepends="
	cmake
	extra-cmake-modules
	gobject-introspection-dev
	gtk+3.0-dev
	gtk4.0-dev
	"
subpackages="$pkgname-dev ${pkgname}3:_gtk3 ${pkgname}4:_gtk4"
options="!check" # no test suites
source="$pkgname-$pkgver.tar.gz::https://github.com/fcitx/fcitx5-gtk/archive/$pkgver.tar.gz"

build() {
	_build 3
	_build 4
	_build libs
}

package() {
	DESTDIR="$pkgdir" cmake --install $pkgname-libs
}

_build() {
	cmake -B $pkgname-$1 \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_SKIP_BUILD_RPATH=true \
		-DENABLE_GTK2_IM_MODULE=OFF \
		-DENABLE_GTK3_IM_MODULE=OFF \
		-DENABLE_GTK4_IM_MODULE=OFF \
		-DENABLE_GTK"$1"_IM_MODULE=ON \
		-DENABLE_SNOOPER=ON \
		-DENABLE_GIR=ON
	cmake --build $pkgname-$1
}

_gtk3() {
	pkgdesc="${pkgdesc/GTK/GTK3}"
	install="$subpkgname.post-install $subpkgname.post-upgrade"
	install -Dt "$subpkgdir"/usr/lib/gtk-3.0/3.0.0/immodules \
		"$builddir"/fcitx5-gtk-3/gtk3/im-fcitx5.so
}

_gtk4() {
	pkgdesc="${pkgdesc/GTK/GTK4}"
	install -Dt "$subpkgdir"/usr/lib/gtk-4.0/4.0.0/immodules \
		"$builddir"/fcitx5-gtk-4/gtk4/libim-fcitx5.so
}

sha512sums="
93bb111e8e3818651ad8319b23e90d299e668fa49cc55b7e4a84b76afe2f5693068f8a7778d19d557187fb2e2c0f58d3dc3102d4eca2c5a034b0b79955c81f00  fcitx5-gtk-5.0.16.tar.gz
"
